using System;
using System.Data;
using System.Data.Odbc;
using System.Data.SqlClient;
using System.Data.OleDb;
using Oracle.DataAccess.Client;
using System.Configuration;
 
namespace DataAccess
{
  public sealed class MultiDBParameter
  {
    private DataProvider providerType;
    private IDbDataParameter[]idbParameters =null;
 
    public MultiDBParameter()
	{
		this.providerType = DBMSProvider.ProviderType;
    }
	public MultiDBParameter(DataProvider ProviderType)
	{
		  this.providerType = ProviderType;
	}
	  
    public IDbDataParameter[] Parameters
    {
      get
      {
        return idbParameters;
      }
	  set
	  {
		  idbParameters = value;
	  }
    }
    public void CreateParameters(int paramsCount)
    {
      idbParameters = new IDbDataParameter[paramsCount];
	  idbParameters = DBManagerFactory.GetParameters(this.providerType, paramsCount);
    }
 
    public void AddParameters(int index, string paramName, object objValue)
    {
      if (index < idbParameters.Length)
      {
		  switch (this.providerType)
		  {
			  case DataProvider.MySQL:
				  idbParameters[index].ParameterName = paramName;
				  idbParameters[index].Value = objValue;
				  break;
			  case DataProvider.SqlServer:
				  idbParameters[index].ParameterName = paramName.Replace("?", "@");
				  idbParameters[index].Value = (objValue == null) ? (object)DBNull.Value : objValue;
				  break;
			  case DataProvider.Oracle:
				  idbParameters[index].ParameterName = paramName.Replace("?", ":");
				  idbParameters[index].Value = objValue;
				  break;
		  }
      }
    }
 
   
  }//class
}

